﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace DataLibrary
{
    public class Ctbl_Nick_Yahoo: IData<tbl_Nick_Yahoo>
    {
        public Ctbl_Nick_Yahoo(String myconnecString) : base(myconnecString) { }

        protected override int InsertOnSubmit(tbl_Nick_Yahoo item, int t)
        {
            int id = -1;
            String proName = "ProNickYahoo";
            id = connec.ExecuteNonQuery(proName, CommandType.StoredProcedure, new SqlParameter("@flag", t),
                new SqlParameter("@"+tbl_Nick_Yahoo.c_Description,item.Description),new SqlParameter("@"+tbl_Nick_Yahoo.c_idNick,item.IdNick),
                new SqlParameter("@"+tbl_Nick_Yahoo.c_isActive,item.IsActive),new SqlParameter("@"+tbl_Nick_Yahoo.c_Nickname,item.Nickname),
                new SqlParameter("@"+tbl_Nick_Yahoo.c_orderId,item.OrderId),new SqlParameter("@"+tbl_Nick_Yahoo.c_Phone,item.Phone));
            return id;
        }

        public override List<tbl_Nick_Yahoo> GetAll(tbl_Nick_Yahoo item)
        {
            throw new NotImplementedException();
        }

        public override tbl_Nick_Yahoo GetItemById(object id)
        {
            return GetAll().SingleOrDefault(p => p.IdNick ==Convert.ToInt32(id));
        }

        public override tbl_Nick_Yahoo GetItem(IDataReader dr)
        {
            tbl_Nick_Yahoo obj = new tbl_Nick_Yahoo();
            obj.IdNick = Convert.ToInt32(dr[tbl_Nick_Yahoo.c_idNick]);
            obj.Description = dr[tbl_Nick_Yahoo.c_Description].ToString();
            obj.Nickname = dr[tbl_Nick_Yahoo.c_Nickname].ToString();
            obj.OrderId = Convert.ToInt32(dr[tbl_Nick_Yahoo.c_orderId]);
            obj.IsActive = Convert.ToInt32(dr[tbl_Nick_Yahoo.c_isActive]);
            obj.Phone = Convert.ToString(dr[tbl_Nick_Yahoo.c_Phone]);
            return obj;
        }

        public override List<tbl_Nick_Yahoo> GetAll()
        {
            String strSql = "select * from " + tbl_Nick_Yahoo.b_TableName + strAsc;
            return GetAll(strSql, CommandType.Text);
        }
    }
}
